﻿//alert = function (msg, fnSuccessful, duration) {
//    duration = isNaN(duration) ? 3000 : duration;
//    var al = document.getElementById("alertbox")
//    while (al.hasChildNodes()) {
//        al.removeChild(al.firstChild);
//    }
//    if (typeof (fnSuccessful) === "function") {
//        showToast2(msg, fnSuccessful, duration);
//    } else {
//        showToast(msg, duration);
//    }
//}
//function showToast(msg, duration) {
//    duration = isNaN(duration) ? 3000 : duration;
//    var m = document.createElement('div');
//    m.id = "alert";
//    m.innerHTML = msg;
//    m.style.cssText = "width:80%; min-width:150px; background:#000; opacity:0.5; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:5px; position:fixed; top:80%; left:10%; z-index:999999; font-weight:bold;";
//    //document.body.appendChild(m);
//    document.getElementById("alertbox").appendChild(m);
//    setTimeout(function () {
//        var d = 0.5;
//        m.style.webkitTransition = '-webkit-transform ' + d
//                + 's ease-in, opacity ' + d + 's ease-in';
//        m.style.opacity = '0';
//        m.style.zIndex = '-100';
//        setTimeout(function () {
//            document.body.removeChild(m)
//        }, d * 3000);
//    }, duration);
//}
//function showToast2(msg, fnSuccessful, duration) {
//    duration = isNaN(duration) ? 3000 : duration;
//    var m = document.createElement('div');
//    m.id = "alert";
//    m.innerHTML = msg;
//    m.style.cssText = "width:80%; min-width:150px; background:#000; opacity:0.5; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:5px; position:fixed; top:80%; left:10%; z-index:999999; font-weight:bold;";
//    //document.body.appendChild(m);
//    document.getElementById("alertbox").appendChild(m);
//    setTimeout(function () {
//        var d = 0.5;
//        m.style.webkitTransition = '-webkit-transform ' + d
//                + 's ease-in, opacity ' + d + 's ease-in';
//        m.style.opacity = '0';
//        m.style.zIndex = '-100';
//        setTimeout(function () {
//            document.body.removeChild(m)
//            fnSuccessful();
//        }, d * 3000);
//    }, duration);
//}


alert = function (options) {
    var defaults = {
        tip: '',
        confirmBtnLbl: '确  定',
        maskColor: '#000',
        cancelCallback: null,
        confirmCallback: null
    };
    var settings = $.extend(defaults, options || {}),
        $this;

    function initialize() {
        var HTML = '<div style="background:#000;opacity:.5;position:fixed;z-index:99999;left:0px;top:0px;width:100%;height:100%;"></div><div style="background-color: #fff;width: 80%;margin: auto;position: fixed;left: 50%;top: 50%;-webkit-transform:translate(-50%,-50%);-moz-transform:translate(-50%,-50%);transform:translate(-50%,-50%);text-align: center;border-radius: 5px;z-index:100000;display:table;"><div style="display:table;width:100%;border-bottom:1px solid #808080;"><div style="padding:10px;width:100%;text-align:center;"><span style="height:auto;min-height:50px;line-height:25px;vertical-align:middle;text-align:center;font-size:16px;color:#000000;padding-left:10px;">' + settings.tip + '</span></div></div><div style="display:table;width:100%;"><span style="display:table-cell;height:40px;line-height:40px;vertical-align:middle;border-left:1px solid #EAEAEA;color:#09f;">' + settings.confirmBtnLbl + '</span></div></div>';
        $this = $(HTML).appendTo($('body'));
        var $btn = $this.children('div:eq(1)');
        $btn.children().eq(0).off('click', confirmBtnClickHandler).on('click', confirmBtnClickHandler);
    }
    function confirmBtnClickHandler() {
        $this.remove();
        if (settings.confirmCallback && typeof settings.confirmCallback == 'function') {
            settings.confirmCallback();
        }
    }
    initialize();
}